﻿#region copyright
//<copyright>
// Copyright(C) 2012 TrackerRealm Corporation
// This file is part of the open source project - Jazz. http://jazz.codeplex.com
// 
// Jazz is open software: you can redistribute it and/or modify it 
// under the terms of the GNU Affero General Public License (AGPL) as published by 
// the Free Software Foundation, version 3 of the License.
// 
// Jazz is distributed in the hope that it will be useful, 
// but WITHOUT ANY WARRANTY; without even the implied warranty 
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
//  See the GNU Affero General Public License (AGPL) for more details.
// 
// You should have received a copy of the GNU General Public 
// License along with Jazz.  If not, see <http://www.gnu.org/licenses/>.
//
// REMOVAL OF THIS NOTICE IS VIOLATION OF THE COPYRIGHT. 
//</copyright>
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Reflection;
using TrackerRealm.Jazz.Common;
using C = TrackerRealm.Jazz.Common.JazzConstants;

namespace TrackerRealm.Jazz.Client
{
    /// <summary>
    /// StateTableEntry describes a single member of state transition table (StateTable).
    /// </summary>
    public class StateTableEntry
    {
        /// <summary>
        /// 
        /// </summary>
        public static readonly StateTableEntry[] EmptyArray = new StateTableEntry[0];
        /// <summary>
        /// 
        /// </summary>
        public static readonly StateTableEntry Empty = new StateTableEntry(jClass.Placeholder, jState.Empty, jState.Empty, "") ;
        #region Factory methods - Create
        /// <summary>]
        /// Create
        /// </summary>
        /// <param name="jclass"></param>
        /// <param name="currentState"></param>
        /// <param name="nextState"></param>
        /// <param name="propertyMethodName"></param>
        /// <returns></returns>
        internal static StateTableEntry Create(jClass jclass, jState currentState, jState nextState, string propertyMethodName)
        {
            return new StateTableEntry(jclass, currentState, nextState, propertyMethodName);
        }
        #endregion
        #region  Constructors
        /// <summary>
        ///  Constructor
        /// </summary>
        /// <param name="jclass"></param>
        /// <param name="currentState"></param>
        /// <param name="nextState"></param>
        /// <param name="propertyMethodName"></param>
        private StateTableEntry(jClass jclass, jState currentState, jState nextState, string propertyMethodName)
        {
            this.Name = currentState.Name + "-" + nextState.Name;
            this.NextState = nextState;
            this.CurrentState = currentState;
            this.JClass = jclass;
            this.MemberInfo = this.JClass.GetJazzMemberInfo(propertyMethodName);
        }
        #endregion
        //
        // Instance properties
        //
        #region Name
        /// <summary>
        /// 
        /// </summary>
        public string Name
        {
            get;
            private set;
        }
        #endregion
        #region JClass
        /// <summary>
        /// 
        /// </summary>
        public jClass JClass
        {
            get;
            private set;
        }
        #endregion
        #region MemberInfo
        /// <summary>
        /// 
        /// </summary>
        public jMemberInfo MemberInfo
        {
            get;
            private set;
        }
        #endregion
        #region CurrentState
        /// <summary>
        /// 
        /// </summary>
        public jState CurrentState
        {
            get;
            private set;
        }
        #endregion
        #region NextState
        /// <summary>
        /// 
        /// </summary>
        public jState NextState
        {
            get;
            private set;
        }
        #endregion
        //
        // Instance Methods
        //
        
        #region ToString
        /// <summary>
        /// Provides information for visual studio when hovering over variables.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return this.GetType().Name + ":'" + this.Name + "'";
        }
        #endregion
    }
}
